<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('标准地址表')"/>
</head>
<!--<style>
    .img-circle {
        border-radius: 0;
    }
</style>-->
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>地址名称：</label>
                            <input type="text" name="dzmc-like"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
           <!-- <a class="btn btn-warning" onclick="makeAllQrcode()">
                <i class="fa"></i> 一键生成三维码
            </a>
            <a class="btn btn-success" onclick="downloadAllQrcode()">
                <i class="fa"></i> 一键下载三维码
            </a>
            <a class="btn btn-success" onclick="">
                <i class="fa"></i> 下载三维码
            </a>-->
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "control/qrcode";

    $(function () {
        var options = {
            url: prefix + "/list",
            modalName: "标准地址",
            sortName: "cjsj",
            sortOrder: "desc",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'dzbm',
                    title: '地址编码',
                    visible: false
                },
                {
                    field: 'dzlx',
                    title: '地址类型',
                    formatter: function (value, row, index) {
                        if (value === 'FW') {
                            return "房屋";
                        } else if (value === 'JZW') {
                            return "建筑物";
                        }
                    },
                },
                {
                    field: 'dzmc',
                    title: '地址名称'
                },
                {
                    title: '三维码',
                    formatter: function (value, row, index) {
                        if (row.haveQrcode) {
                            return ('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="seeQrcode(\'' + row.dzbm + '\')"> 查看三维码</a> ');
                        } else {
                            return "-";
                        }
                    }
                },
                //$.table.imageView("data:image/jpeg;base64," + row.qrcode)
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        /*if (!row.qrcode) {
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="makeQrcode(\'' + row.dzbm + '\')"><i class="fa fa-qrcode"></i> 门牌三维码</a> ');
                        }*/
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="qrcodeDisplay(\'' + row.dzbm + '\')"> 公开信息</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*
     *生成三维码
     */
    /*function makeQrcode(dzbm) {
        $.post($.common.setURL(prefix + "/makeQrcode/" + dzbm), function (res) {
            if (res.success) {
                layer.msg(res.message, {icon: 1});
                $.table.refresh();
            }
        })
    }*/

    /*
     *生成所有三维码
     */
    /*function makeAllQrcode() {
        $.post($.common.setURL(prefix + "/makeAllQrcode"), function (res) {
            if (res.success) {
                layer.msg(res.message, {icon: 1});
                $.table.refresh();
            }
        })
    }*/

    /*
     * 下载所有三维码
     */
    function downloadAllQrcode() {
        $.post($.common.setURL(prefix + "/downloadAllQcode"));
    }

    /*
     *三维码公开信息
     */
    function qrcodeDisplay(dzbm) {
        var url = $.common.setURL(ctx + "control/display/setDisplay/" + dzbm);
        open("公开信息设置", url);
    }

    /*
     *查看三维码
     */
    function seeQrcode(dzbm) {
        var options = {
            title: table.options.modalName + "三维码",
            width: "402",
            height: "512",
            url: $.common.setURL(prefix + "/seeQrcode/" + dzbm),
            skin: 'layui-layer-gray',
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }

    function open(title, url) {
        layer.open({
            type: 2,
            area: ['800px', '500px'],
            title: title,
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function (index) {
                return true;
            }
        });
    }

</script>
</body>
</html>
